package com.ibeeking.found.upms.cs.rest.controller.v1;

import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.constants.GlobalConstant;
import com.ibeeking.found.common.constants.HeaderNounConstant;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.upms.cs.rest.service.ICsPermissionService;
import com.ibeeking.found.upms.service.common.vo.CurrentPermissionVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.data.TreeFastUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName PermissionController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-01 18:15
 **/
@RestController
@RequestMapping("/b/permission/v1")
public class CsPermissionController {

    @Resource
    private ICsPermissionService permissionServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询有效权限菜单树")
    @GetMapping(value = "/queryEffectiveList")
    public List<CurrentPermissionVO> queryEffectiveList(@LoginUser(isFull = true) CurrentUser currentUser, HttpServletRequest request) {
        List<CurrentPermissionVO> currentPermissionVos = permissionServiceImpl.queryEffectiveList(currentUser, request.getHeader(HeaderNounConstant.JWT_JTI));
        return TreeFastUtils.listToTree(currentPermissionVos, GlobalConstant.PARENT_ID);
    }
}
